package net.anzhuo.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsReportLogMapper;
import net.anzhuo.entity.GsReportLog;
import net.anzhuo.service.GsReportLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class GsReportLogServiceImpl implements GsReportLogService {

	@Autowired
	private GsReportLogMapper gsReportLogMapper;

	@Override
	public PaginationVO<GsReportLog> getListWithPage(GsReportLog gsReportLog) {
		PaginationVO<GsReportLog> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsReportLogMapper.getListWithPage(gsReportLog));
		paginationVO.setTotalCount(gsReportLogMapper.getCount(gsReportLog));
		paginationVO.setTotalPage((gsReportLogMapper.getCount(gsReportLog) + gsReportLog.getPageSize() -1)  / gsReportLog.getPageSize());
		paginationVO.setPageNo(gsReportLog.getPageNo());
		return paginationVO;
	}

	@Override
	public GsReportLog getById(Long id) {
		return gsReportLogMapper.getById(id);
	}

	@Override
	public List<GsReportLog> getList() {
		return gsReportLogMapper.getList();
	}

	@Override
	public List<GsReportLog> getList(GsReportLog gsReportLog) {
		return gsReportLogMapper.getListByQuery(gsReportLog);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsReportLog gsReportLog) {
		gsReportLogMapper.update(gsReportLog);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsReportLog gsReportLog) {
		gsReportLogMapper.save(gsReportLog);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsReportLog gsReportLog = gsReportLogMapper.getById(id);
		if (gsReportLog == null) {
//			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsReportLogMapper.update(gsReportLog);
	}
}
